import { Injectable } from '@nestjs/common';
import { PageDto } from './dto';
import { User } from '@app/db/entity/User';
import { FindOptionsWhere } from 'typeorm';
import { DbService } from '../../db/db.service';

@Injectable()
export class UserService {
    constructor(
        private readonly db:DbService,
        
    ){
    }


    async page(dto:PageDto) {
           
        let result:PaginationResult<User> = {
            total : 0,
            rows : []
        }

        let where:FindOptionsWhere<User> = {
            
        }

        
        if(dto.nickname) {
            where.nickname = dto.nickname
        }

        result.total = await this.db.user.count(where)

        if(result.total > 0) {
            result.rows = await this.db.user.pagination(dto.pageNo, dto.pageSize, where, null, {id : 'DESC'})
        }
        

        return result

    }

    
}
